package com.hopes.bizz.risk.tenant.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hopes.bizz.risk.setting.entity.RiskCalendarEntity;
import com.hopes.bizz.risk.setting.service.RiskCalendarService;
import com.hopes.bizz.risk.tenant.service.TenantConfigInitService;
import com.hopes.boss.admin.api.entity.SysTenant;
import com.hopes.boss.common.data.tenant.TenantContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/8/14 10:57
 * @Description:
 */
@Slf4j
@Service
public class RiskCalendarTenantInitServiceImpl implements TenantConfigInitService {
    @Autowired
    private RiskCalendarService riskCalendarService;

    @Override
    public String getName() {
        return "初始化日历";
    }

    @Override
    public void init(SysTenant tenant) {
        Long tenantId = tenant.getId();

        List<RiskCalendarEntity> list = riskCalendarService.list(Wrappers.<RiskCalendarEntity>lambdaQuery().eq(RiskCalendarEntity::getTenantId, TenantContextHolder.getAdminTenantId()));
        for (RiskCalendarEntity riskCalendarEntity : list) {
            riskCalendarEntity.setId(null);
            riskCalendarEntity.setTenantId(tenantId);
        }

        riskCalendarService.saveBatch(list);
    }
}
